package org.test.jiazi_1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.test.jiazi_1.common.constant.StatusConstant;
import org.test.jiazi_1.common.exception.BusinessException;
import org.test.jiazi_1.mapper.CourseMapper;
import org.test.jiazi_1.pojo.entity.Course;
import org.test.jiazi_1.service.CourseService;

/**
 * 课程信息表(Course)表服务实现类
 *
 * @author 2251300222 唐文涛
 * @since 2025-10-24 13:27:54
 */
@Slf4j
@Service("courseService")
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Override
    public void endCourse(Integer id) {
        boolean update = lambdaUpdate()
                .set(Course::getStatus, 1)
                .eq(Course::getId, id)
                .eq(Course::getStatus, StatusConstant.ENABLE)
                .update();
        //更新课程状态为已结束
        if (!update) {
           throw new BusinessException(500, "课程不存在或已结束");
        }
    }
}
